package com.moxing.admin.controller;


import com.moxing.admin.common.dto.RestResponseDTO;
import com.moxing.admin.common.dto.request.LoginRequestParam;
import com.moxing.admin.common.entity.User;
import com.moxing.admin.service.LoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@Api(tags = "/api/login",description = "登录管理")
@RestController
@RequestMapping("/api/login")
public class LoginController {


    @Autowired
    private LoginService loginService;
    /**
     * 登录
     * @return
     */
    @ApiOperation(value = "登录",httpMethod = "POST")
    @PostMapping("/login")
    @ResponseBody
    public RestResponseDTO login(@RequestBody LoginRequestParam param) {
        try {
            User login = loginService.login(param);
            return RestResponseDTO.success(login);
        }catch (Exception e){
            log.error("登录失败{}",e);
            return RestResponseDTO.validFail(e.getMessage());
        }
    }
}
